package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;
import edu.pku.sei.act.model.mote.MoteForPackage;
import edu.pku.sei.act.model.mote.PackageI;
import edu.pku.sei.gmp.model.concept.GMPModelElement;

public class CreateMoteForPackageCommand extends Command{
	
	private PackageI packageI;
	private MoteForPackage mote;
	
	public CreateMoteForPackageCommand(GMPModelElement parent, MoteForPackage mote ) {
		super("Create Mote");
		this.packageI = (PackageI)parent;
		this.mote = mote;
	}
	
	public boolean canExecute() {
		return packageI !=null && mote != null ;
	}
	
	public void execute() {
		if (packageI != null) {
			mote.setContainer(packageI);
			packageI.getMote().add(mote);
		}
	}
	
	public void undo() {
		if (packageI != null) {
			packageI.getMote().remove(mote);
		}
		mote.setContainer(null);
	}
	
	public void redo(){
		this.execute();
	}

}
